package org.example.managementsystem.service;

import org.example.managementsystem.model.ProviderComplaint;
import org.example.managementsystem.model.ProviderComplaintReview;
import org.example.managementsystem.repository.ProviderComplaintDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 供应商投诉服务层
 * @author 王振祎
 * @date 2025-05-20
 */
@Service
public class ProviderComplaintService {
    private final ProviderComplaintDao providerComplaintDao;

    @Autowired
    public ProviderComplaintService(ProviderComplaintDao providerComplaintDao) {
        this.providerComplaintDao = providerComplaintDao;
    }

    /**
     * 提交供应商投诉
     */
    public void submitComplaint(
            String defectiveMaterial,
            boolean isApproved,
            String provoderName,
            String description,
            String complainantJobNumber) {

        // 创建投诉对象,更新投诉表
        ProviderComplaint complaint = new ProviderComplaint();
        complaint.setDefectiveMaterial(defectiveMaterial);
        complaint.setApproved(isApproved);
        complaint.setProviderName(provoderName);
        complaint.setDescription(description);
        complaint.setComplainantJobNumber(complainantJobNumber);

    }

    public void submitComplaint(ProviderComplaint complaint){
        providerComplaintDao.insertComplaint(complaint);
    }

    /**
     * 更新投诉状态
     */
    public void updateComplaint(ProviderComplaint complaint) {
        providerComplaintDao.updateComplaint(complaint);
    }

    /**
     * 获取所有投诉
     */
    public List<ProviderComplaint> getAllComplaints() {
        return providerComplaintDao.getAllComplaints();
    }


    /**
     * 获取所有未审核的投诉
     */
    public List<ProviderComplaint> getAllUnreviewedComplaints() {
        return providerComplaintDao.getAllUnreviewedComplaints();
    }

    /**
     * 根据ID获取投诉
     */
    public ProviderComplaint getComplaintById(int complaintId) {
        return providerComplaintDao.getComplaintById(complaintId);
    }

    /**
     * 根据Id删除投诉
     */
    public void deleteComplaint(int complaintId) {
        providerComplaintDao.deleteComplaint(complaintId);
    }

}